<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML表格与表单示例</title>
    <style>
        body {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            font-family: Arial, sans-serif;
            line-height: 1.6;
        }
        h2 {
            color: #2c3e50;
            border-bottom: 2px solid #3498db;
            padding-bottom: 10px;
        }
        /* 表格样式 */
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }
        table, th, td {
            border: 1px solid #ddd;
        }
        th, td {
            padding: 12px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
        caption {
            font-weight: bold;
            margin-bottom: 10px;
            font-size: 1.1em;
        }
        tfoot {
            background-color: #f9f9f9;
        }
        
        /* 表单样式 */
        form {
            margin: 20px 0;
        }
        fieldset {
            border: 1px solid #ddd;
            padding: 20px;
            border-radius: 5px;
        }
        legend {
            font-weight: bold;
            color: #2c3e50;
            padding: 0 10px;
        }
        label {
            display: inline-block;
            width: 120px;
            vertical-align: top;
        }
        input, select, textarea {
            width: 60%;
            padding: 8px;
            margin: 5px 0 15px 0;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        input[type="radio"], 
        input[type="checkbox"] {
            width: auto;
            margin-right: 10px;
        }
        input[type="file"] {
            padding: 5px 0;
            border: none;
        }
        button {
            background-color: #3498db;
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 10px;
        }
        button[type="reset"] {
            background-color: #e74c3c;
        }
        button[type="button"] {
            background-color: #95a5a6;
        }
        button:hover {
            opacity: 0.9;
        }
        .radio-group, .checkbox-group {
            margin-bottom: 15px;
        }
        .radio-group label, .checkbox-group label {
            width: auto;
            margin-right: 15px;
        }
    </style>
</head>
<body>
    <h1>HTML表格与表单演示</h1>

    <!-- 表格部分 -->
    <h2>3. 表格</h2>
    <!-- 使用语义化表格结构，包含表头、表体和表脚 -->
    <table>
        <caption>学生信息表</caption> 
        <thead>
            <tr>
                <th>学号</th> 
                <th>姓名</th> 
                <th>专业</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>2021001</td> 
                <td>小明</td> 
                <td>计算机科学</td>
            </tr>
            <tr>
                <td>2021002</td> 
                <td>小红</td> 
                <td>软件工程</td>
            </tr>
            <tr>
                <td>2021003</td> 
                <td>小刚</td> 
                <td>数据科学</td>
            </tr>
        </tbody>
        <tfoot> 
            <tr>
                <td colspan="3">注：此为示例数据，共3条记录</td> 
            </tr>
        </tfoot>
    </table>

    <!-- 表单部分 -->
    <h2>4. 表单</h2>
    <!-- 表单用于收集用户输入，action指定提交地址，method指定提交方式 -->
    <form action="/submit-handler" method="POST"> 
        <fieldset> 
            <legend>用户登录</legend> 

            <label for="username">用户名:</label> 
            <input type="text" id="username" name="username" required placeholder="请输入用户名"><br>

            <label for="password">密码:</label>
            <input type="password" id="password" name="password" required><br>

            <label for="avatar">上传头像:</label>
            <input type="file" id="avatar" name="avatar" accept="image/*"><br>

            <label for="country">国家:</label>
            <select id="country" name="country">
                <option value="">--请选择--</option>
                <option value="china" selected>中国</option>
                <option value="usa">美国</option>
                <option value="uk">英国</option>
            </select><br>

            <div class="radio-group">
                <label>性别:</label>
                <input type="radio" id="male" name="gender" value="male">
                <label for="male">男</label>
                <input type="radio" id="female" name="gender" value="female">
                <label for="female">女</label>
            </div>

            <div class="checkbox-group">
                <label>兴趣（可多选）:</label>
                <input type="checkbox" id="coding" name="hobbies" value="coding" checked>
                <label for="coding">编程</label>
                <input type="checkbox" id="music" name="hobbies" value="music">
                <label for="music">音乐</label>
                <input type="checkbox" id="sports" name="hobbies" value="sports">
                <label for="sports">运动</label>
            </div>

            <label for="message">个人简介:</label><br>
            <textarea id="message" name="message" rows="4" cols="40" placeholder="介绍一下你自己..."></textarea><br>

            <button type="submit">提交</button>
            <button type="reset">重置</button>
            <button type="button" onclick="alert('Hello!')">普通按钮</button> 
        </fieldset>
    </form>
</body>
</html>
    